package com.example.springdataelastci.controller;

import com.example.springdataelastci.model.BlogModel;
import com.example.springdataelastci.model.vo.BlogSelVo;
import com.example.springdataelastci.service.IBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 测试
 *
 * @author heyangyang
 * @since 2023-11-03
 */
@RestController
@RequestMapping("blob")
public class BlogController {

    @Autowired
    private IBlogService blogService;

    /**
     * 新增/修改 文档信息
     *
     * @param blogModel 数据
     * @return
     * @throws IOException
     */
    @PostMapping("upsert")
    public String insert(@RequestBody BlogModel blogModel) throws IOException {
        blogService.insert(blogModel);
        return "insert success";
    }

    /**
     * 根据主键获取文档信息
     *
     * @param id 逐渐id
     * @return
     * @throws IOException
     */
    @GetMapping("{id}")
    public BlogModel getById(@PathVariable("id") String id) throws IOException {
        return blogService.getById(id);
    }

    /**
     * 删除文档
     * @param idList
     * @return
     */
    @DeleteMapping("delete")
    public String delete(@RequestBody List<String> idList) throws IOException {
        blogService.deleteByIdList(idList);
        return "delete success";
    }

    /**
     * 获取文档信息
     */
    @PostMapping("page")
    public List<BlogModel> page(@RequestBody BlogSelVo blogSelVo) throws IOException {
        return blogService.page(blogSelVo);
    }
}
